using System;
using System.Collections.Generic;
using Headspring.Training.DataAccess.Impl;
using Headspring.Training.Domain.Model;
using NHibernate;
using NUnit.Framework;

namespace Headspring.Training.DataAccess.IntegrationTests
{
	[TestFixture]
	public class ZDataLoader : RepositoryBase
	{
		[Test, Category("DataLoader")]
		public void PopulateDatabase()
		{
			ISession session = getSession();
			ITransaction transaction = session.BeginTransaction();
			TestHelper.ClearTables();

			//Trainer1
			Employee jpalermo = new Employee("jpalermo", "Jeffrey", "Palermo", "jpalermo@headspringsystems.com");
			jpalermo.SetAllNotificationPreferencesTo(NotificationType.Both);
			session.SaveOrUpdate(jpalermo);

			//Trainer2
			Employee jbogard = new Employee("jbogard", "Jimmy", "Bogard", "jbogard@headspringsystems.com");
			session.SaveOrUpdate(jbogard);

			//Student1
			Employee cyao = new Employee("cyao", "Cedric", "Yao", "raspar@gmail.com");
			session.SaveOrUpdate(cyao);

			//Student2
			Employee vmo = new Employee("vmo", "vicky", "mo", "vicky.mo@mcfa.com");
			session.SaveOrUpdate(vmo);
			//Student3

			Employee jessex = new Employee("jessex", "Julia", "Essex", "jmessex@utmb.edu");
			session.SaveOrUpdate(jessex);

			WorkOrder jworkorder = new WorkOrder();
			jworkorder.Number = "J467";
			jworkorder.Assignee = jpalermo;
			jworkorder.Creator = jessex;
			session.SaveOrUpdate(jworkorder);

			//Student4
			Employee ashaw = new Employee("ashaw", "Anthony", "Shaw", "ashaw@rpionline.com");
			session.SaveOrUpdate(ashaw);

			//Student5
			Employee dstein = new Employee("dstein", "David", "Stein", "djsopa@gmail.com");
			session.SaveOrUpdate(dstein);

			WorkOrder orderDStein = new WorkOrder();
			orderDStein.Number = Guid.NewGuid().ToString().Substring(0, 5).ToUpper();
			orderDStein.Creator = dstein;
			orderDStein.Assignee = jpalermo;
			orderDStein.CreatedDate = DateTime.Now;
			orderDStein.Status = WorkOrderStatus.Assigned;
			orderDStein.Title = "Work Order starting in status " + WorkOrderStatus.Assigned.ToString();
			orderDStein.Description = "Foo, foo, foo, foo " + WorkOrderStatus.Assigned.ToString();
			session.SaveOrUpdate(orderDStein);


			Employee lchan = new Employee(@"lchan", @"Lam", @"Chan", @"lamchakchan@gmail.com");
			session.SaveOrUpdate(lchan);

			WorkOrder order1 = new WorkOrder();
			order1.Number = Guid.NewGuid().ToString().Substring(0, 5).ToUpper();
			order1.Creator = lchan;
			order1.Assignee = jpalermo;
			order1.CreatedDate = DateTime.Now;
			order1.Status = WorkOrderStatus.Draft;
			order1.Title = "Work Order starting in status " + WorkOrderStatus.Draft.ToString();
			order1.Description = "Foo, foo, foo, foo " + WorkOrderStatus.Draft.ToString();
			session.SaveOrUpdate(order1);

			//Student6
			Employee cvo = new Employee("cvo", "Carolyn", "Vo", "carolyn.vo@springbox.com");
			session.SaveOrUpdate(cvo);
			WorkOrder wo = new WorkOrder();
			wo.Number = Guid.NewGuid().ToString().Substring(0, 5).ToUpper();
			wo.Creator = cvo;
			wo.Assignee = jpalermo;
			wo.CreatedDate = DateTime.Now;
			wo.Status = WorkOrderStatus.Draft;
			wo.Title = "Work order starting in status " + WorkOrderStatus.Draft;
			wo.Description = "Work order kaka for Thursday kaka";
			session.SaveOrUpdate(wo);

			//Student7
			Employee bmc = new Employee("bmelcran", "Brad", "Mellen-Crandell", "bmellencrandell@rpionline.com");
			session.SaveOrUpdate(bmc);

			WorkOrder bmcOrder = new WorkOrder();
			bmcOrder.Number = "BMC01";
			bmcOrder.Creator = bmc;
			bmcOrder.Assignee = jpalermo;
			bmcOrder.CreatedDate = DateTime.Parse("5/10/2007 1:00");
			bmcOrder.Status = WorkOrderStatus.Assigned;
			bmcOrder.Title = "A Workorder: whoo";
			bmcOrder.Description = "Stop surfing and get to work.";
			session.SaveOrUpdate(bmcOrder);

			//Student8
			Employee sflanders = new Employee("sflanders", "Shawn", "Flanders", "shawnflanders@hotmail.com");
			sflanders.MobileNumber = "123456789";
			session.SaveOrUpdate(sflanders);

			//Student9
			Employee khariharan = new Employee("khariharan", "Karthik", "Hariharan", "khariharan@telligent.com");
			session.SaveOrUpdate(khariharan);
			WorkOrder khariharanWorkorder = new WorkOrder();
			khariharanWorkorder.Number = Guid.NewGuid().ToString().Substring(0, 5).ToUpper();
			khariharanWorkorder.Assignee = jpalermo;
			khariharanWorkorder.Creator = khariharan;
			session.SaveOrUpdate(khariharanWorkorder);


			//Student10
			Employee kjackson = new Employee("kjackson", "Kenneth", "Jackson", "ken.jackson@catapultsystems.com");
			session.SaveOrUpdate(kjackson);

			WorkOrder kjacksonWorkorder = new WorkOrder();
			kjacksonWorkorder.Number = Guid.NewGuid().ToString().Substring(0, 5).ToUpper();
			kjacksonWorkorder.Assignee = jpalermo;
			kjacksonWorkorder.Creator = kjackson;
			session.SaveOrUpdate(kjacksonWorkorder);

			//Student11
			Employee rsankholkar = new Employee("RSankholkar", "Rohit", "Sankholkar", "rsankholkar@gmail.com");
			session.SaveOrUpdate(rsankholkar);

			WorkOrder myorder = new WorkOrder();
			myorder.Number = Guid.NewGuid().ToString().Substring(0, 5).ToUpper();
			myorder.Creator = rsankholkar;
			myorder.Assignee = jpalermo;
			myorder.CreatedDate = DateTime.Now;
			session.SaveOrUpdate(myorder);

			//Student12
			Employee sureshs = new Employee("Sureshs", "Suresh", "Sundararajan", "surejan@gmail.com");
			session.SaveOrUpdate(sureshs);
			//Student13

			//Student14

			Employee darrendave = new Employee("darrendave", "Darren", "Burns", "darrendave@gmail.com");
			session.SaveOrUpdate(darrendave);

			WorkOrder order14 = new WorkOrder();
			order14.Number = Guid.NewGuid().ToString().Substring(0, 5).ToUpper();
			order14.Creator = darrendave;
			order14.Assignee = jpalermo;
			order14.CreatedDate = DateTime.Now;
			order14.Status = WorkOrderStatus.Draft;
			order14.Title = "Work Order starting in status " + WorkOrderStatus.Draft.ToString();
			order14.Description = "Teach the world to code " + WorkOrderStatus.Draft.ToString();
			session.SaveOrUpdate(order14);

			//Student15

			foreach (WorkOrderStatus status in WorkOrderStatus.GetAllItems())
			{
				WorkOrder order = new WorkOrder();
				order.Number = Guid.NewGuid().ToString().Substring(0, 5).ToUpper();
				order.Creator = jpalermo;
				order.Assignee = jbogard;
				order.CreatedDate = DateTime.Now;
				order.Status = status;
				order.Title = "Work Order starting in status " + status.ToString();
				order.Description = "Foo, foo, foo, foo " + status.ToString();
				session.SaveOrUpdate(order);
			}


			transaction.Commit();
			session.Dispose();
		}

		[Test]
		public void foo()
		{
//			while (true)
//			{
//				ISession session = getSession();
//				IQuery query = session.CreateQuery("from Employee emp");
//				query.SetCacheable(true);
//				IList<Employee> list = query.List<Employee>();
//				foreach (Employee employee in list)
//				{
//					Console.WriteLine(employee);
//				}
//
//				session.Dispose();
//			}
		}
	}
}